home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 2497 < prev    next >
Encoding:
Text File  |  1996-08-05  |  4.6 KB  |  123 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: nntp.coast.net!torn!utnut!utgpu!normb
  3. From: normb@gpu.utcc.utoronto.ca (Norman Baccari)
  4. Subject: Re: Opening Libraries "Quietly"
  5. Message-ID: <DM2uyG.Muz@gpu.utcc.utoronto.ca>
  6. Organization: UTCC Public Access
  7. Distribution: All
  8. Date: Thu, 1 Feb 1996 03:27:52 GMT
  9.  
  10. >
  11. >
  12. > : Two Questions...
  13. >
  14. > : From what I understand, when calling OpenLib() this causes the
  15. > : library thats being opened to call its own init proceedure.
  16. > : I want to open the library to get Ver/Rev and id_string and
  17. > : quietly leave without affecting anything. When I do this now
  18. > : some libraries do there "init thing" and will try and run
  19. > : themselves. Toolmanager.library will do this and so does
  20. > : vmm.library. In an extreme case the system will crash on the
  21. > : OpenLib() as it does when the amos.library opened. Is there a
  22. > : way to get the info I want from any disk based library,
  23. > : quietly & legally?
  24. >
  25. > First, LoadSeg() the library. This will give you a BPTR to the library
  26. > code. Use the BADDR() macro to convert this to an APTR and cast the
  27. > result to LONG *. Add 2. Then cast the result to struct Resident * and
  28. > read the values out of the Resident structure. i.e.
  29. >
  30. >       BPTR libseg;
  31. >       UWORD libver, librev;
  32. >       struct Resident *libres;
  33. >
  34. >       if( libseg = LoadSeg(libname) ) /* use _full_ pathname */
  35. >       {
  36. >               /* get pointer to embedded Resident structure */
  37. >               libres = (struct Resident *)((LONG *)BADDR(libseg)+2);
  38. >
  39. >               /* check that it really is a library */
  40. >               if( ((ULONG *)libres)[-1] != 0x70ff4e75 ||
  41. >                   libres->rt_MatchWord != RT_MATCHWORD ||
  42. >                   libres->rt_MatchPtr != (APTR)libres )
  43. >                       /* rt_MatchPtr is wrong - I forget the real name */
  44. >               {
  45. >                       /* copy fields */
  46. >                       libver = libres->rt_Version;
  47. >                       librev = libres->rt_Revision;
  48.                                          ^^^^^^^^^^^
  49.                                          not defined in resident struct
  50. >               }
  51. >               else
  52. >                       /* not a library */
  53. >
  54. >               UnLoadSeg(libseg);
  55. >       }
  56. >       else
  57. >               /* handle the error */
  58. >
  59. > You could also fetch the version string while you're at it.
  60. >
  61. > : I also need to prevent "non libraries" from being opened. The
  62. > : library being opened is a user passed argument. If the user
  63. > : passed a file thats not a library then OpenLib() will crash.
  64. > : Can I interogate the file internally to detect if its actually
  65. > : a library that can be opened by OpenLib()?
  66.  
  67. > See the condition I just added to the code example. This will allow only
  68. > libraries and devices (which are just a special type of library) to be
  69. > looked at.
  70.  
  71. > : Thanks in advance....
  72. > :
  73. > : =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  74. > : Norman Baccari   normb@gpu.utcc.utoronto.ca    Toronto,Ontario Canada
  75. > : =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  76.  
  77.  
  78. > I hope this works.
  79. >
  80. > Ben.
  81.  
  82. > --
  83. > Ben Hutchings, student. Finger me on worc0223@sable.ox.ac.uk for
  84. > various info.
  85. > email: benjamin.hutchings@worc.ox.ac.uk  WWW:
  86. > http://sable.ox.ac.uk/~worc0223/
  87. > Users of the world unite! You have nothing to lose but your Micro$oft
  88. > software
  89.  
  90. Thanks Ben for the code. I've plugged it in and it seems to work for
  91. getting the version, and IdString. But its seems that using this
  92. method trades one problem for another. OpenLib() can cause some
  93. unstable behaviour but I get Version, Revision and id_String.
  94. To eliminate the unstable behaviour I can use LoadSeg() but I
  95. dont get the Revision. Am I to believe that there is no way to
  96. to obtain all of Version,Revision, and id_string info in a stable
  97. manner??
  98.  
  99. I seem to also have another problem using LoadSeg(). When I use
  100. OpenLib() I can check the existance of an id_string by saying
  101.  
  102.  
  103. if(LibBase->lib_IdString)    /* or if strlen(IdString)>0  then... */
  104.   /* I have an id_string */
  105. else
  106.  /* No Id_String */
  107.  
  108. When I do this with the rt_IdString  in the Resident
  109. structure and there is no IdString I get an enforcer hit, even
  110. though the no IdString condition evaluates as true. How can I
  111. check for the existance of the IdString without getting an enforcer
  112. hit when there isnt one?
  113.  
  114. Once again, thanks.
  115.  
  116.  ---------------------------------------------------------------------
  117.   Norman Baccari             | "OK team! You start coding.
  118.   normb@gpu.utcc.utoronto.ca | I'll go see what the user specs are."
  119.   Toronto,Ontario,Canada     |
  120.  ---------------------------------------------------------------------
  121.  
  122.  
  123.